package me.khrystal.cleanmaster.dialogs;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;

/**
 * usage:
 * author: kHRYSTAL
 * create time: 16/9/13
 * update time:
 * email: 723526676@qq.com
 */
public class ProgressDialogFragment extends DialogFragment {

    int mIndeterminateDrawable;
    String mMessage;
    static View mContentView;
    private ProgressDialog mProgressDialog;

    public static ProgressDialogFragment newInstance(int indeterminateDrawable, String message) {

        ProgressDialogFragment f = new ProgressDialogFragment();
        Bundle args = new Bundle();
        args.putInt("indeterminateDrawable", indeterminateDrawable);
        args.putString("message", message);
        f.setArguments(args);

        return f;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mIndeterminateDrawable = getArguments().getInt("indeterminateDrawable");
        mMessage = getArguments().getString("message");
        mProgressDialog = new ProgressDialog(getActivity(), AlertDialog.THEME_HOLO_LIGHT);

        if (mIndeterminateDrawable > 0) {
            mProgressDialog.setIndeterminateDrawable(getActivity()
                .getResources().getDrawable(mIndeterminateDrawable));
        }
//        set Dialog message
        if (mMessage != null) {
            mProgressDialog.setMessage(mMessage);
        }

        return mProgressDialog;
    }

    /**
     * set Message
     * @param message dialogfragment message
     */
    public void setMessage(String message) {
        if (!TextUtils.isEmpty(message) && mProgressDialog != null) {
            // TODO: 16/9/13
            mProgressDialog.setMessage(mMessage);
        }
    }
}
